'''oto/client.py

This module contains the client.
'''

__authors__ = ['Ryan Rousseau <ryan.rousseau@gmail.com>']
__license__ = '''Oranges to Oranges
Copyright (C) 2006  Ryan Rousseau

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
'''

import time
from game import *

__all__ = ['GameClient']

class GameClient(object):
    def __init__(self, name):
        self.name = name
        self.key = str(time.time())
        self.creds = (self.name, self.key)
        self.game = None

    def set_name(self, name):
        self.name = name
        self.creds = (self.name, self.key)

    def connect(self, uri):
        self.game = Pyro.core.getProxyForURI(uri)
        return self.game.connect(self.creds)

    def disconnect(self):
        if self.game:
            vals = self.game.disconnect(self.creds)
            self.game = None
            return vals
        return ('Error', 'You are not connected to a game')

    def set_deck(self, deck):
        self.game.set_deck(self.creds, deck)

    def start_game(self):
        self.game.start_game(self.creds)

    def chat(self, message):
        if self.game:
            self.game.chat(self.creds, message)

    def get_player_tree_info(self):
        info = {}
        players = self.game.get_players()
        for player in players:
            info[player] = self.game.get_winnings(player)
        return info

    def get_is_judge(self):
        return self.game.is_judge(self.creds)

    def get_hand(self):
        return self.game.get_hand(self.creds)

    def get_submitted_cards(self):
        return self.game.get_submitted_cards(self, self.creds)

    def submit_card(self, card):
        return self.game.submit_card(self.creds, card)
